package com.ruge.util;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageInfo;
import java.util.Collections;
import java.util.List;

public class PageHelperUtils {

    public static <T> PageInfo<T> memoryPage(List<T> list, int pageNum, int pageSize) {
        if (list == null || list.isEmpty()) {
            return new PageInfo<>(Collections.emptyList());
        }
        
        // 计算分页数据
        int total = list.size();
        int start = Math.max((pageNum - 1) * pageSize, 0);
        int end = Math.min(start + pageSize, total);
        
        // 创建 Page 对象并设置数据
        Page<T> page = new Page<>(pageNum, pageSize);
        page.addAll(list.subList(start, end));
        page.setTotal(total);
        
        return new PageInfo<>(page);
    }
}